{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"500 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## _*Entangled Measurement*_ \n",
    "\n",
    "The latest version of this notebook is available on https://github.com/QISKit/qiskit-tutorial.\n",
    "\n",
    "\n",
    "***\n",
    "### Contributors\n",
    "Ikko Hamamura\n",
    "\n",
    "### Qiskit Package Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'qiskit': '0.10.3',\n",
       " 'qiskit-terra': '0.8.1',\n",
       " 'qiskit-ignis': '0.1.1',\n",
       " 'qiskit-aer': '0.2.1',\n",
       " 'qiskit-ibmq-provider': '0.2.2',\n",
       " 'qiskit-aqua': '0.5.1'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import qiskit\n",
    "qiskit.__qiskit_version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Entanglement of Observable"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Entanglement of quantum states is a key concept in quantum world.\n",
    "The entanglement was introduced in [Entanglement](../qis_intro/entanglement_introduction.ipynb) and deepened in [Testing Entanglement](../qis_intro/entanglement_testing.ipynb).\n",
    "The Bell state $\\left(\\left|00\\right\\rangle+\\left|11\\right\\rangle\\right)/\\sqrt{2}$ shows perfect correlations for any basis measurement.\n",
    "This nonlocal correlation is a resource of quantum information processing including a quantum computer.\n",
    "If you want to decide whether a given quantum state is entangled or not, [Bell-CHSH inequality](../qis_intro/entanglement_testing.ipynb#CHSH-Inequality-) is useful.\n",
    "The violation of the Bell-CHSH inequality implies that the state is entangled.\n",
    "\n",
    "On the other hand, there is entanglement of quantum observables.\n",
    "In this tutorial, we will show the detection way of the entanglement of measurement.\n",
    "More specifically, we use dual version of Bell-CHSH inequality proposed in [here](https://arxiv.org/abs/1709.07987) to detect entanglement of observables.\n",
    "This is an inverse process of original one."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Imports useful packages \n",
    "from itertools import product\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "# importing Qiskit\n",
    "from qiskit import Aer, IBMQ\n",
    "from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n",
    "from qiskit import execute\n",
    "from qiskit.providers.ibmq import least_busy\n",
    "from qiskit.tools.monitor import job_monitor\n",
    "from qiskit.quantum_info.analyzation.average import average_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.load_accounts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The most famous entangled measurement is Bell measurement.\n",
    "The Bell measurement is an inverse process of a preparation of Bell states.\n",
    "The Bell measurement can be found in [quantum teleportation and superdense coding](../qis_intro/teleportation_superdensecoding.ipynb)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Creating registers\n",
    "qa = QuantumRegister(1, 'alice')\n",
    "qb = QuantumRegister(1, 'bob')\n",
    "c = ClassicalRegister(2, 'c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAADRCAYAAADCDHkJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAdHUlEQ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5BT0QkcQx6IiKJY9ATEUkcg56ISOIY9EREEsegJyKSOAY9EZHEMeiJiCSOQU9EJHEMeiIiiWPQExFJHIOeiEji/gfTuyCTjRMUmQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 481.6x258.86 with 1 Axes>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Bell Measurement\n",
    "bell_measurement = QuantumCircuit(qa, qb, c)\n",
    "bell_measurement.cx(qa, qb)\n",
    "bell_measurement.h(qa)\n",
    "bell_measurement.measure(qa[0], c[0])\n",
    "bell_measurement.measure(qb[0], c[1])\n",
    "bell_measurement.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Dual Bell-CHSH inequality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let $\\mathsf{M}_0$ be a nonlocal observable operator (POVM element).\n",
    "Here, our problem is to decide whether a given observable is entangled.\n",
    "\n",
    "We assume each local system is a qubit system.\n",
    "Alice and Bob prepare two states individually.\n",
    "Let $\\rho^A_i$ and $\\rho^B_j$ be Alice's and Bob's quantum states (density operators) respectively.\n",
    "When Alice and Bob prepare states $\\rho^A_i$ and $\\rho^B_j$ and perform a nonlocal measurement,\n",
    "they obtain an outcome $0$ with the probability $\\operatorname{tr}\\left[\\rho^A_i\\otimes\\rho^B_j\\mathsf{M}_0\\right]$.\n",
    "\n",
    "\n",
    "Let's introduce [dual Bell-CHSH inequality](https://arxiv.org/abs/1709.07987) to detect entanglement of observables.\n",
    "We define a quantity as\n",
    "\n",
    "$$\n",
    "D = E(\\rho^A_0, \\rho^B_0, \\mathsf{M}_0) + E(\\rho^A_0, \\rho^B_1, \\mathsf{M}_0) + E(\\rho^A_1, \\rho^B_0, \\mathsf{M}_0) - E(\\rho^A_1, \\rho^B_1, \\mathsf{M}_0),\n",
    "$$\n",
    "\n",
    "where $E(\\rho^A_i, \\rho^B_j, \\mathsf{M}_0) = 4 \\operatorname{tr}\\left[\\left(\\rho^A_i-\\frac{I}{2}\\right)\\otimes\\left(\\rho^B_j-\\frac{I}{2}\\right)\\mathsf{M}_0\\right]$.\n",
    "If the given measurement with a condition $\\operatorname{tr}\\left[\\frac{I}{4} \\mathsf{M}_0\\right]\\leq \\frac{1}{4}$ is not entangled (separable), the following inequality\n",
    "\n",
    "$$\n",
    "-2 \\leq D \\leq 2\n",
    "$$\n",
    "\n",
    "holds.\n",
    "This inequality is called the dual version of  Bell-CHSH inequality (or dual Bell-CHSH inequality for short).\n",
    "The original one is a separability criterion for entangled states, but the dual version is a separability criterion for entangled observables.\n",
    "\n",
    "It is difficult to prepare the completely mixed state $\\frac{I}{2}$ directly, so we calculate another form.\n",
    "For a qubit system, there exists a unique orthogonal state $\\left|\\psi^\\perp\\right\\rangle$ for each state $\\left|\\psi\\right\\rangle$.\n",
    "It is enough to consider the case the states of each system are pure. (i.e. $\\rho^A_i=\\left|\\psi^A_i\\right\\rangle\\left\\langle\\psi^A_i\\right|$ and $\\rho^B_i=\\left|\\psi^B_i\\right\\rangle\\left\\langle\\psi^B_i\\right|$.)\n",
    "In this case,\n",
    "\n",
    "$$\n",
    "E(\\rho^A_i, \\rho^B_j, \\mathsf{M}_0) = \\left\\langle\\psi^A_i\\psi^B_j\\middle|\\mathsf{M}_0\\middle|\\psi^A_i\\psi^B_j\\right\\rangle\n",
    "-\\left\\langle{\\psi^A_i}^\\perp\\psi^B_j\\middle|\\mathsf{M}_0\\middle|{\\psi^A_i}^\\perp\\psi^B_j\\right\\rangle\n",
    "-\\left\\langle\\psi^A_i{\\psi^B_j}^\\perp\\middle|\\mathsf{M}_0\\middle|\\psi^A_i{\\psi^B_j}^\\perp\\right\\rangle\n",
    "+\\left\\langle{\\psi^A_i}^\\perp{\\psi^B_j}^\\perp\\middle|\\mathsf{M}_0\\middle|{\\psi^A_i}^\\perp{\\psi^B_j}^\\perp\\right\\rangle.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, we give these states to demonstrate the violation of dual Bell-CHSH inequality ($\\left|D\\right|>2$).\n",
    "Alice prepares eigenstates of the following matrices:\n",
    "$$\n",
    "Z\n",
    "= \\begin{pmatrix}\n",
    "1 & 0 \\\\\n",
    "0 & -1\n",
    "\\end{pmatrix},\n",
    "$$\n",
    "and\n",
    "$$\n",
    "X\n",
    "= \\begin{pmatrix}\n",
    "0 & 1 \\\\\n",
    "1 & 0\n",
    "\\end{pmatrix}.\n",
    "$$\n",
    "In a similar way, Bob prepares eigen states of the following matrices:\n",
    "$$\n",
    "W = \\frac{1}{\\sqrt{2}}\\left( Z + X \\right)\n",
    "= \\frac{1}{\\sqrt{2}}\\begin{pmatrix}\n",
    "1 & 1 \\\\\n",
    "1 & -1\n",
    "\\end{pmatrix},\n",
    "$$\n",
    "and\n",
    "$$\n",
    "V = \\frac{1}{\\sqrt{2}}\\left( Z - X \\right)\n",
    "= \\frac{1}{\\sqrt{2}}\\begin{pmatrix}\n",
    "1 & -1 \\\\\n",
    "-1 & -1\n",
    "\\end{pmatrix}.\n",
    "$$\n",
    "We note that eigenstates corresponding to different eigenvalues must be orthogonal.\n",
    "The quantum circuit of each preparation procedure is given by"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<qiskit.circuit.instructionset.InstructionSet at 0x128f67ef0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alice = {}\n",
    "bob = {}\n",
    "\n",
    "# eigenvalue\n",
    "alice['+'] = QuantumCircuit(qa, qb, c) # do nothing\n",
    "alice['-'] = QuantumCircuit(qa, qb, c)\n",
    "alice['-'] .x(qa)\n",
    "\n",
    "bob['+'] = QuantumCircuit(qa, qb, c) # do nothing\n",
    "bob['-'] = QuantumCircuit(qa, qb, c)\n",
    "bob['-'].x(qb)\n",
    "\n",
    "# matrix\n",
    "alice['Z'] = QuantumCircuit(qa, qb, c) # do nothing\n",
    "\n",
    "alice['X'] = QuantumCircuit(qa, qb, c)\n",
    "alice['X'].h(qa)\n",
    "\n",
    "bob['W'] = QuantumCircuit(qa, qb, c)\n",
    "bob['W'].h(qb)  \n",
    "bob['W'].t(qb)\n",
    "bob['W'].h(qb)\n",
    "bob['W'].s(qb)\n",
    "\n",
    "bob['V'] = QuantumCircuit(qa, qb, c)\n",
    "bob['V'].h(qb)  \n",
    "bob['V'].tdg(qb)\n",
    "bob['V'].h(qb)\n",
    "bob['V'].s(qb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alice prepares an eigenstate of $Z$ with an eigenvalue $+1$ and Bob prepares an eigenstate of $V$ with an eigenvalue $+1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUwAAADRCAYAAACn4Yt2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAT10lEQVR4nO3df0zU9x3H8RfSddRxx50IrkwPhp1Zq5FfkpFlCYo61tGFGnTFrDhlxBmTLprgYFubuK5DNLJfTf9hVEmAxCwhDsgS0AW1ibNUOaAb6z8Nv6SxZUc5D2jqLHz3R+NFptUP3Mnd6fOR3B98v3ffz/vO9pnv944fUZZlWQIA3NeSUA8AAJGCYAKAIYIJAIYIJgAYIpgAYIhgAoAhggkAhggmABgimABgiGACgCGCCQCGCCYAGCKYAGCIYAKAIYIJAIYIJgAYIpgAYIhgAoAhggkAhggmABgimABgiGACgCGCCQCGCCYAGCKYAGCIYAKAIYIJAIYIJgAYIpgAYIhgAoAhggkAhggmABgimABgiGACgCGCCQCGCCYAGCKYAGAoaMHMz89XTU2N/+v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z2VRUVCSPxxPqsQCECYJ5m+rqarW0tKirq0ujo6OSpJKSkhBPBSBchG0wL168qM2bN8tut8vhcGjHjh0PfM3a2lpVVFQoNTVVcXFxOnbsmNrb2zU8PPzA1wYQ/sIymM3Nzdq2bZv279+vsbExXb16VWVlZfM6RnV1tdavX298f6/Xq5GREWVlZfm3rV69Wna7XX19ffNaG8DDKeyCOT09rZ/+9Keqra1VUVGRYmJiZLPZlJ+fL0nasmWLEhIS9Nprr93zOJWVlXr33XeN152cnJQkxcXFzdnucDjk8/nm+SwAPIweC/UA/+/ChQuKiopSYWHhXffX19fr73//u/89xmCx2WySpOvXr8/Z7vV6Zbfbg7rW3VQerX3gawC4v+qKvV+4L+yC6fF45HQ6FRUVddf9K1eufCDrOhwOuVwuud1upaenS5IGBgbk8/nmdWm/UPf6RwIQHsLukjwzM1ODg4Nqa2vT7OysvF6vOjo6FmXtvXv36ujRoxocHJTP51NFRYXy8/OVkpKyKOsDCG9hd4a5bt061dXVqby8XDt37pTNZlNpaan/PUxTVVVVampqUn9/v/FjKisrNTExoezsbN24cUNbt25VY2PjfJ/CgnBJDoSHe13tRVmWZS3iLEFRX1+v0dFRvfzyy6EeBcAjJOKCWVpaqq6uLt24cUNPP/202traQj0SgEdExAUTAEIl7D70AYBwRTABwBDBBABDBBMADBFMADBEMAHAEMEEAEMEEwAMEUwAMEQwAcAQwQQAQwQTAAwRTAAwRDABwBDBBABDBBMADBFMADBEMAHAEMEEAEMEEwAMEUwAMEQwAcAQwQQAQwQTAAz9D2wWSdR6243WAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 421.4x258.86 with 1 Axes>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc = alice['+'] + alice['Z'] + bob['+'] + bob['V']\n",
    "qc.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Alice prepares an eigenstate of $X$ with an eigenvalue $-1$ and Bob prepares an eigenstate of $W$ with an eigenvalue $+1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUwAAADRCAYAAACn4Yt2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAWDklEQVR4nO3df0yT+R0H8HfFnZxHS2v5ERkUhjeyO4mUXxm5LOuJ5xqHSzXoxOxgyAgzbrtgAivb7hLndghGbrdLLksYp2RAYrYxD9gW0AX0EuUYUuBy7JLFFPlhVK7YhwI3nQfP/rjQ2KnwLS19Wn2/kuePfp8+z+fTh/LO9+nTHypZlmUQEdGK1indABFRqGBgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJYmASEQliYBIRCWJgEhEJWq90A6Ss8vJyDA0NBbyu0WjE22+/vaptleoZ8K1vCn2cYT7lhoaGAh4+vtZUomcl61Lw4AyTYDQacfHixYDVe/nll33eR6B7BvzTN4U2zjCJiAQxMImIBDEwiYgEMTCJiAQxMImIBDEwiYgEMTCJiAQxMImIBPktMM1mM+rq6ty3v/Wtb+G9997z1+79orGx0as3H2dmZqKrq2vtGgpBc3NziI6Oxp///Gf32H/+8x+89NJL2LdvHxYXFxXs7vHi4uLQ0NDgMSbLMjQaDc6dO6dQVxRq/BaYg4ODyMjIcN8+f/48fvCDH/hr92tiYWEBlZWViI6OhlqtRn5+PhwOh3u9xWJBe3u7gh0Gn4iICFRUVOD48eOQZRkLCwv47ne/iw0bNqClpQXr1gXfScuNGzdw8+ZNGI1Gj3G73Y7Z2VlkZWUp1BmFGr88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iIReYJSUl6Ovrw7179/DCCy+go6ND6ZaI6CkRcoFJRKSUoLvoQ0QUrBiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIIYmEREghiYRESCGJhERIL+ByROnhAkgkU7AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 421.4x258.86 with 1 Axes>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc = alice['-'] + alice['X'] + bob['+'] + bob['W']\n",
    "qc.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is the setting of our experiment."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Violation of the dual Bell-CHSH inequality"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's show the violation of the dual Bell-CHSH inequality."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A quantum circuit of -X+V.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAl0AAADRCAYAAAD2bwehAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deVRTZ/4/8HdEERRCKKIWFRFaBEGMItqpjiAu1LpQDy44Ki6j0eIy2mrBViulHQRP3aaoU8SWGXHqVK3FZQaVo+K4UZSllWr7c0CW1lZRYgCrVcjvD75kSNkSEu5N4P06xyPc7fnkkhvePPe590rUarUaRERERNSqOohdABEREVF7wNBFREREJACGLiIiIiIBMHQR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QIUNQUFCAY8eOobq6GkqlEidPnhSkbYVCgbi4OBQUFEClUiEiIgJBQUFwcXERpH0iIjKcRCJh4CKTZHI9Xd7e3khMTMSaNWswa9Ys2NraYuHChZoxXbqKiYnB/v37kZeXp/M6kZGRKCsrg5+fH548eYJx48YhOTlZ35fQIjy9SEREZP6aOnNllg+8TkpKQklJCdavXy92KUREREQ6MbvQtXDhQmRkZODJkyfw9PTEsWPHxC6JiIiIqFlmF7qIiIiIzJHJDaQnIiIiaosYuoiIiIgEwNBFREREJACGLiIiIiIBMHQRERERCYChi4iIiEgADF1EREREAmDoIiIiIhIAQxcRERGRABi6iIiIiATA0EVEREQkAIYuIiIiIgEwdBEREREJgKGLiIiISAAMXUREREQCYOgiIiIiEgBDFxEREZEAGLqIiIiIBMDQRURERCQAhi4iIiIiATB0EREREQmAoYuIiIhIAAxdRERERAJg6CIiIiISwP8Huctnn4YcPzQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 782.6x258.86 with 1 Axes>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "backend = Aer.get_backend('qasm_simulator')\n",
    "shots = 1024\n",
    "circuits = {}\n",
    "\n",
    "for a_sign, a_basis, b_sign, b_basis in product(['+', '-'], ['Z', 'X'], ['+', '-'], ['V', 'W']):\n",
    "    name = a_sign + a_basis + b_sign + b_basis\n",
    "    circuits[name] = QuantumCircuit(qa, qb, c)\n",
    "    circuits[name] += alice[a_sign]\n",
    "    circuits[name] += alice[a_basis]\n",
    "    circuits[name] += bob[b_sign]\n",
    "    circuits[name] += bob[b_basis]  \n",
    "    circuits[name].barrier(qa)\n",
    "    circuits[name].barrier(qb)\n",
    "    circuits[name] += bell_measurement\n",
    "\n",
    "# Example\n",
    "print('A quantum circuit of -X+V.')\n",
    "circuits['-X+V'].draw(output='mpl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "job = execute(list(circuits.values()), backend=backend, shots=shots)\n",
    "result = job.result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, we have to check which measurement outcome satisfies the condition $\\operatorname{tr}\\left[\\frac{I}{4} \\mathsf{M}_0\\right]<\\frac{1}{4}$.\n",
    "The completely mixed state $\\frac{I}{4}$ can be simulated by the average of all state preparations in current setting.\n",
    "At least one outcome satisfies this condition."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.lines.Line2D at 0x128ec1f28>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAELCAYAAADDZxFQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAcWUlEQVR4nO3de5RcdZnu8e9DEPDCTRIdBUJAIwoKIgF0dKEyoFE0ERSJigcdnCgjikfxkIwjaEQBUbziSJQcGTxHQEcwYhTDJTgKQm4uIGgOAQMkAyIESAQDBJ7zx97tFE119e6md+/q7uezVq3a+7cv9VYt6Df7d5VtIiIietus6QAiIqI7JUFERERbSRAREdFWEkRERLSVBBEREW1t3nQAQ2X8+PGeNGlS02FERIwoS5cuvcf2hHbHRk2CmDRpEkuWLGk6jIiIEUXSbX0dSxVTRES0lQQRERFtJUFERERbSRAREdFWvwlChaMknVTuT5S0f/2hRUREk6o8QXwLeBXwrnJ/A3BWbRFFRERXqNLN9QDbr5C0HMD2fZK2qDmuiIhoWJUniEcljQMMIGkC8HiVm0uaKmmlpFWSZrU5/nFJN0m6XtLlknZpOfaYpN+Vr/kVv09ERAyRKk8QXwcuAp4j6fPAO4BP93dRmVTOAg4B1gCLJc23fVPLacuBKbYf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dK6msN52uB50j6W4O4pGcAhwK/7vQFKrqcogH8dttLer1uGIL7xxiTJ4gY9WxfLOnbwFmS9gAuofhv/0jgfcDsljEQFwHfkPQvFNVFbwf27HXLnkbqD0o6H3io/AP8FeB/AP8p6fMUvZheAjzT9hdtXyrpauACSbMonjhOoOiRdMYQfNV/p2iwXlR21b2Votprf+Au218Zgs+IMSRPEDFW/DPwTxRdXn8C/BDYDZhuu3XFtLnAV4GPAhdSVM2c0noj27dR/GE/HPgN5bgI23+m6KW0vLzHJcBM4PaWy98GLCyP/5CiDeGgXl1cB8X2RuD15f0/C/yS4ulpMkWX2YgByYpyERHRVp4gIiKirSSIiIhoKwkiIiLaSoKIiIi2kiAiIqKtJIiIiGgrCSIiItpKgoiIiLb+PxlrCLa74oO0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "completely_mixed = {'00': 0, '01': 0, '10': 0, '11': 0}\n",
    "for a_sign, a_basis, b_sign, b_basis in product(['+', '-'], ['Z', 'X'], ['+', '-'], ['V', 'W']):\n",
    "    name = a_sign + a_basis + b_sign + b_basis\n",
    "    completely_mixed['00'] += average_data(result.get_counts(circuits[name]), {'00': 1})/16\n",
    "    completely_mixed['01'] += average_data(result.get_counts(circuits[name]), {'01': 1})/16\n",
    "    completely_mixed['10'] += average_data(result.get_counts(circuits[name]), {'10': 1})/16\n",
    "    completely_mixed['11'] += average_data(result.get_counts(circuits[name]), {'11': 1})/16\n",
    "    \n",
    "plt.bar(list(completely_mixed.keys()), list(completely_mixed.values()), width=0.5)\n",
    "plt.xlabel('Outcome', fontsize=15)\n",
    "plt.ylabel('Probability for the completely mixed state', fontsize=10)\n",
    "plt.axhline(y=0.25, color='red', linewidth=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following function calculates $$E(\\rho^A_i, \\rho^B_j, \\mathsf{M}_0) = \\left\\langle\\psi^A_i\\psi^B_j\\middle|\\mathsf{M}_0\\middle|\\psi^A_i\\psi^B_j\\right\\rangle\n",
    "-\\left\\langle{\\psi^A_i}^\\perp\\psi^B_j\\middle|\\mathsf{M}_0\\middle|{\\psi^A_i}^\\perp\\psi^B_j\\right\\rangle\n",
    "-\\left\\langle\\psi^A_i{\\psi^B_j}^\\perp\\middle|\\mathsf{M}_0\\middle|\\psi^A_i{\\psi^B_j}^\\perp\\right\\rangle\n",
    "+\\left\\langle{\\psi^A_i}^\\perp{\\psi^B_j}^\\perp\\middle|\\mathsf{M}_0\\middle|{\\psi^A_i}^\\perp{\\psi^B_j}^\\perp\\right\\rangle.\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def E(result, observable: dict, a_basis: str, b_basis: str) -> float:\n",
    "    val = 0\n",
    "    str2int = lambda x: 1 if x == '+' else -1\n",
    "    for a_sign, b_sign in product(['+', '-'], ['+', '-']):\n",
    "        name = a_sign + a_basis + b_sign + b_basis\n",
    "        sign = str2int(a_sign) * str2int(b_sign)\n",
    "        val += sign * average_data(result.get_counts(circuits[name]), observable)\n",
    "    return val"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's calculate\n",
    "$$\n",
    "D = E(\\rho^A_0, \\rho^B_0, \\mathsf{M}_0) + E(\\rho^A_0, \\rho^B_1, \\mathsf{M}_0) + E(\\rho^A_1, \\rho^B_0, \\mathsf{M}_0) - E(\\rho^A_1, \\rho^B_1, \\mathsf{M}_0).\n",
    "$$\n",
    "\n",
    "We can arbitrarily choose the position of this minus sign.\n",
    "In the following function, we choose this so that $|D|$ is larger."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def D(result, outcome: str) -> float:\n",
    "    val = 0\n",
    "    for a_basis, b_basis in product(['Z', 'X'], ['V', 'W']):\n",
    "        if outcome[0] == outcome[1] and a_basis == 'X' and b_basis == 'V':\n",
    "            sign = -1\n",
    "        elif outcome[0] != outcome[1] and a_basis == 'X' and b_basis == 'W':\n",
    "            sign = -1\n",
    "        else:\n",
    "            sign = 1\n",
    "        val += sign * E(result, {outcome: 1}, a_basis=a_basis, b_basis=b_basis)\n",
    "    return val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D is equal to 2.7705078125 for the outcome 00.\n"
     ]
    }
   ],
   "source": [
    "for outcome in ['00', '01', '10', '11']:\n",
    "    if completely_mixed[outcome] <= 1/4: # check the condition\n",
    "        print('D is equal to {} for the outcome {}.'.format(D(result, outcome), outcome))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the probability for completely mixed state is equal to of less than $1/4$ and the value $D$ is more than $2$ (or less than $-2$), we now show the existence of an entangled observable!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Experiment in real Quantum Computer (Optional)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want to perform this experiment with a real quantum computer, please run the following codes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the best backend is ibmqx2\n"
     ]
    }
   ],
   "source": [
    "device_shots = 1024\n",
    "device_name = least_busy(IBMQ.backends(simulator=False)).name()\n",
    "device = IBMQ.get_backend(device_name)\n",
    "\n",
    "print(\"the best backend is \" + device_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Job Status: job has successfully run\n"
     ]
    }
   ],
   "source": [
    "backend = least_busy(IBMQ.backends(simulator=False))\n",
    "job = execute(list(circuits.values()), backend=backend, shots=device_shots)\n",
    "job_monitor(job)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D is equal to 1.91796875 for the outcome 01.\n",
      "D is equal to -1.849609375 for the outcome 11.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAELCAYAAADDZxFQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAccElEQVR4nO3de5RcdZnu8e9DkIsYICbRUSBcNKKgIBKCjq6gDCCKJoIiqHjUwYkwoni8HIIXUMQhgKKiOBIhA+IZAzqCEaPI3UEQkhAXEJRDiAGSARnuESaBwHP+2LuxKKqrd3d6d1V3P5+1atW+/Xa9XavTb/bvKttEREQ026DTAURERHdKgoiIiJaSICIioqUkiIiIaCkJIiIiWtqw0wEMlgkTJni77bbrdBgREcPK4sWL77c9sdW5EZMgtttuOxYtWtTpMCIihhVJd/Z2LlVMERHRUhJERES0lAQREREtJUFERERLfSYIFQ6TdFy5P0nS1PpDi4iITqryBPE94A3A+8r91cAZtUUUERFdoUo31z1tv07SEgDbD0naqOa4IiKiw6o8QTwpaQxgAEkTgadrjSoiIjquSoI4HbgQeJGkrwHXACfVGlVERHRcn1VMtv+vpMXAPwAC3mX7j7VHNsS2m/XLTodQ2YrZB3Q6hIgYBfpMEJLOs/1B4E8tjkVExAhVpYpp58adsj1i93rCiYiIbtHrE4SkY4HPA5tKepSiegngCWDOEMQWEX1I1WjUqdcnCNsn2R4LnGp7c9tjy9d428cOYYwREdEBfVYx2T5W0jhJUyVN63lVubmk/SXdJmmZpFktzn9a0q2SbpJ0uaRtG849JekP5Wt+/36siIhYX1UaqT8KHA1sDfwBeD1wHbB3H+XGUIy43hdYCSyUNN/2rQ2XLQGm2H5c0pHAKcAh5bn/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ntU2xfIula4HxJsyieOD5L0SPp1EH4UX9I0WB9VdlVdzlFtddU4F7b3xyEz4hRJE8QMVr8M/BPFF1efw78BNgBmGG7ccW0OcC3gE8CF1BUzZzYeCPbd1L8YT8I+B3luAjb/03RS2lJeY+LgZnAXQ3F3wVcWp7/CUUbwt5NXVwHxPYa4C3l/b8C/Ibi6WkyRZfZiH7JinIREdFSniAiIqKlJIiIiGgpCSIiIlpKgoiIiJaSICIioqUkiIiIaCkJIiIiWkqCiIiIlv4/C4MOyLdgijQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "result = job.result()\n",
    "completely_mixed = {'00': 0, '01': 0, '10': 0, '11': 0}\n",
    "for a_sign, a_basis, b_sign, b_basis in product(['+', '-'], ['Z', 'X'], ['+', '-'], ['V', 'W']):\n",
    "    name = a_sign + a_basis + b_sign + b_basis\n",
    "    completely_mixed['00'] += average_data(result.get_counts(circuits[name]), {'00': 1})/16\n",
    "    completely_mixed['01'] += average_data(result.get_counts(circuits[name]), {'01': 1})/16\n",
    "    completely_mixed['10'] += average_data(result.get_counts(circuits[name]), {'10': 1})/16\n",
    "    completely_mixed['11'] += average_data(result.get_counts(circuits[name]), {'11': 1})/16\n",
    "\n",
    "plt.bar(list(completely_mixed.keys()), list(completely_mixed.values()), width=0.5)\n",
    "plt.xlabel('Outcome', fontsize=15)\n",
    "plt.ylabel('Probability for the completely mixed state', fontsize=10)\n",
    "plt.axhline(y=0.25, color='red', linewidth=1)\n",
    "\n",
    "for outcome in ['00', '01', '10', '11']:\n",
    "    if completely_mixed[outcome] <= 1/4: # check the condition\n",
    "        print('D is equal to {} for the outcome {}.'.format(D(result, outcome), outcome))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## References\n",
    "\n",
    "For more details, please see the original paper including an application to quantum teleportation and generalization to a higher-dimensional Hilbert space.\n",
    "* [IH, Separability criterion for quantum effects, Phys. Lett. A 382 (36) (2018) 2573–2577](https://doi.org/10.1016/j.physleta.2018.06.043)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
